﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Babel.ParserGenerator;

namespace dragonangel.phpProject.Language.DSL
{
    public class CodeClass : CodeExpression
    {
        public CodeClass(string className, LexLocation begin, LexLocation end)
            : base(begin, end, true)
        {
            this.name = className;
        }

        protected string name;
        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        protected string baseType;
        public string BaseType
        {
            get { return baseType; }
            set { baseType = value; }
        }

        protected List<string> interfaces = new List<string>();
        public List<string> Interfaces
        {
            get { return interfaces; }
            set { interfaces = value; }
        }

        public string Iface
        {
            get { return string.Join(",", interfaces.ToArray()); }
            set
            {
                foreach (string item in value.Split(','))
                {
                    interfaces.Add(item.Trim());
                }
            }
        }


        protected IList<CodeMember> members = new List<CodeMember>();
        public IList<CodeMember> Members
        {
            get { return members; }
            set { members = value; }
        }

        public override CodeExpression GetExpression(int line, int col)
        {
            foreach (CodeMember exp in members)
            {
                CodeExpression result = exp.GetExpression(line, col);
                if (result != null)
                    return result;
            }
            return base.GetExpression(line, col);
        }

        public override CodeExpression GetFirstParentContainingMember(int line, int col)
        {
            if (IsInScope(line, col))
            {
                foreach (CodeMember exp in members)
                {
                    CodeExpression result = exp.GetFirstParentContainingMember(line, col);
                    if (result != null)
                        return result;
                }
            }
            return base.GetFirstParentContainingMember(line, col);
        }

    }
}
